<template>
  <div style="height:100%;width:100%;position:relative;">
      <div class="pagetop">
          <template>
              <div style="width:100%;">
                  <div style="float:left;width:60%">
                      <table style="font-size:12px" class="table1style">
                          <tr>
                              <td>报告单元</td>
                              <td>
                                  <rm-ddl-rptunit prgno="LIS118" :appendtobody="true" v-model="Qrptunitid" filterable clearable @change="QrptunitChange" :targetId="true" ref="rptunitSelect"></rm-ddl-rptunit>
                              </td>
                              <td>报告项目</td>
                              <td>
                                  <el-select v-model="rptitemcode" @change="QrptitemChange" filterable clearable placeholder="输入代码或名称可快速查找" ref="rptitemSelect">
                                      <el-option v-for="(item,index) in itemOptions" :value="item.value" :label="item.label + ' [' + item.nameen+']'" :key="index">
                                          <span style="float: left">{{ item.label }}</span>
                                          <span style="float: right; color: #8492a6; font-size: 13px">{{ item.nameen }}</span>
                                      </el-option>
                                  </el-select>
                              </td>
                              <td style="background:#2db7f5;color:white">提示：年龄双击开窗</td>
                          </tr>
                      </table>
                  </div>
                  <div style="float:left;width:40%;">
                      <table style="float:right">
                          <tr>
                              <td>
                                  <el-button icon="el-icon-search" @click="InitPageData" type="primary">
                                      查询</el-button>
                              </td>
                              <td>
                                  <el-button @click="ShowCopyDia()" icon="el-icon-files">复制</el-button>
                              </td>
                              <td>
                                  <el-button icon="el-icon-plus" @click="operatemdl(1)">新增</el-button>
                              </td>
                              <td>
                                  <el-button icon="el-icon-delete" @click="operatemdl(3)">删除</el-button>
                              </td>
                              <td>
                                  <el-button icon="el-icon-document" @click="saverecord">保存</el-button>
                              </td>
                          </tr>
                      </table>
                  </div>
              </div>
          </template>
      </div>
      <div class="pagecenter">
          <rm-layout-left :fixsize="300" :splitwidth="5" :minfixsize="200" :maxflxsize="2000">
              <template v-slot:fix>
                  <div class="tree">
                      <el-tree style="font-size: 14px" :props="props" :load="loadNode" node-key="nodeid" lazy :default-expanded-keys="defaultExpandKeys" @node-click="tree_checkchange_event" :highlight-current="true" ref="treenodes" @node-expand="tree_expand" @node-collapse="tree_collapse">
                          <span class="custom-tree-node" slot-scope="{ node, data }" @mouseenter="treeenter(node)" @mouseleave="treeleave(node)" style="width:100%;">
                              <span class="enumText" :style="node.level == 4 ? '': 'font-weight:bold'">{{ data.name }}</span>
                              <span v-if="showButton && node.id == currentid" style="margin-left:20px;">
                                  <el-button v-if="node.level == 1" @click.stop="ShowAllGroup(node)">{{ node.isall ? '隐藏未设危急值的工作组' : '显示所有工作组' }}</el-button>
                                  <el-button v-if="node.level == 2" @click.stop="ShowAllRptunit(node)">{{ node.isall ? '隐藏未设危急值的报告单元' : '显示所有报告单元' }}</el-button>
                                  <el-button v-else-if="node.level == 3" @click.stop="ShowAllRptitem(node)">{{ node.isall ? '隐藏未设危急值的报告项目' : '显示所有报告项目' }}</el-button>
                              </span>
                          </span>
                      </el-tree>
                  </div>
              </template>
              <template>
                  <div class="middle-center" style="height:100%">
                      <vxe-table show-overflow ref="xTable" height="auto" :loading="loading" :data.sync="tableData" :keyboard-config="keyConfig" show-header-overflow :edit-config="{trigger: 'click', mode: 'cell',showStatus:true,showIcon:false,activeMethod:cellactiveMethod}" @edit-closed="editChange" :header-cell-class-name="headerCellClassName" :row-class-name="rowClassName" highlight-current-row highlight-hover-row resizable border size="mini" @cell-dblclick="opendialog" @current-change="currentChangeEvent" :mouse-config="{selected: true}">
                          <vxe-table-column field="seq" title="顺序" width="50" header-align="center" align="center">
                          </vxe-table-column>
                          <vxe-table-column field="rptunitname" title="报告单元" width="120" header-align="center">
                              <template v-slot="{row}">
                                  <div>
                                      <div v-if="!!row.rptunitname"> {{row.rptunitname}}&nbsp;&nbsp;[{{row.rptunitid}}]</div>
                                      <div v-else>{{row.rptunitid}}</div>
                                  </div>
                              </template>
                          </vxe-table-column>
                          <vxe-table-column field="rpt_itemname" title="报告项目" width="200" header-align="center">
                              <template v-slot="{row}">
                                  <div>
                                      <div v-if="!!row.rpt_itemname">{{row.rpt_itemname}}&nbsp;&nbsp;[{{row.itemcode_en}}]</div>
                                      <div v-else>{{row.itemcode_en}}</div>
                                  </div>
                              </template>
                          </vxe-table-column>
                          <vxe-table-column field="rpt_itemcode" title="报告项目代码" width="100" header-align="center"></vxe-table-column>
                          <vxe-table-column field="patsex" title="性别" width="60" header-align="center" :edit-render="{name: 'select', options: sexOptions}" align="center">
                          </vxe-table-column>
                          <vxe-table-column field="ageyear1" title="年龄1岁数" width="80" header-align="center" :edit-render="{name: 'input',autoselect:true}" :formatter="formatterFun" align="center"></vxe-table-column>
                          <vxe-table-column field="ageyear2" title="年龄2岁数" width="80" header-align="center" :edit-render="{name: 'input',autoselect:true}" :formatter="formatterFun" align="center">
                          </vxe-table-column>
                          <vxe-table-column field="specimen_name" title="标本类型(双击)" width="130" header-align="center" :edit-render="{name: 'input'}" :formatter="formatterFun">
                          </vxe-table-column>
                          <vxe-table-column field="deptname" title="科室(双击)" width="110" header-align="center" :edit-render="{name: 'input'}" :formatter="formatterFun"> </vxe-table-column>
                          <vxe-table-column field="deptsubjectname" title="科室专业类别(双击)" width="125" header-align="center" :edit-render="{name: 'input'}" :formatter="formatterFun">
                          </vxe-table-column>
                          <vxe-table-column field="diag_icd" title="诊断ICD10" width="100" header-align="center" :edit-render="{name: 'input'}" :formatter="formatterFun">
                              <template v-slot:edit="{ row }">
                                  <el-input type="text" v-model="row.diag_icd" clearable></el-input>
                              </template>
                          </vxe-table-column>
                          <vxe-table-column field="physicyclename" title="生理周期(双击)" width="130" header-align="center" :edit-render="{name: 'input'}" :formatter="formatterFun">
                          </vxe-table-column>
                          <vxe-table-column field="hospname" title="医院(双击)" width="110" header-align="center" :edit-render="{name: 'input'}" :formatter="formatterFun">
                          </vxe-table-column>
                          <vxe-table-column field="limit_l" title="危急值低值" width="80" header-align="center" :edit-render="{name: 'input'}" align="center">
                          </vxe-table-column>
                          <vxe-table-column field="limit_h" title="危急值高值" width="80" header-align="center" :edit-render="{name: 'input'}" align="center">
                          </vxe-table-column>
                          <!-- <vxe-table-column field="warn_l" title="警示值低值" width="80" header-align="center" :edit-render="{name: 'input'}" align="center">
                          </vxe-table-column>
                          <vxe-table-column field="warn_h" title="警示值高值" width="80" header-align="center" :edit-render="{name: 'input'}" align="center">
                          </vxe-table-column> -->
                          <vxe-table-column field="limit_rule" title="上次比较危急值(双击)" width="150" header-align="center" :edit-render="{name: 'input'}">
                          </vxe-table-column>
                          <vxe-table-column field="txtresultlist" title="危急值文字结果列表(双击)" width="170" header-align="center">
                          </vxe-table-column>
                          <!-- <vxe-table-column field="warnresultlist" title="警示值文字结果列表(双击开窗)" width="170" header-align="center">
                          </vxe-table-column> -->
                          <vxe-table-column field="onlyfirst" sortable title="入院首次上报后不再上报" width="150" show-overflow align="center">
                              <template v-slot="{ row }">
                                  <el-checkbox v-model="row.onlyfirst" true-label="1" false-label="0"></el-checkbox>
                              </template>
                          </vxe-table-column>
                          <vxe-table-column field="alert_rule" title="再次上报变动范围(双击)" width="150" header-align="center" :edit-render="{name: 'input'}">
                          </vxe-table-column>
                          <vxe-table-column field="resetbypatwardflag" sortable title="更换病区就重置上报" width="150" show-overflow align="center">
                              <template v-slot="{ row }">
                                  <el-checkbox v-model="row.resetbypatwardflag" true-label="1" false-label="0"></el-checkbox>
                              </template>
                          </vxe-table-column>
                          <template v-slot:fix>
                              <div v-show="Qrptunitid && rptitemcode" class="table-bottom">
                                  <el-button class="el-button--310" icon="el-icon-sort" @click="resetSeq()">排序</el-button>
                                  <el-button class="el-button--310" icon="el-icon-top" @click="tabledatafirst()">首位</el-button>
                                  <el-button class="el-button--310" icon="el-icon-top-right" @click="tabledataup()">上移</el-button>
                                  <el-button class="el-button--310" icon="el-icon-bottom-right" @click="tabledatadown()">下移</el-button>
                                  <el-button class="el-button--310" icon="el-icon-bottom" @click="tabledatalast()">末位</el-button>
                              </div>
                          </template>
                      </vxe-table>
                  </div>
              </template>
          </rm-layout-left>
      </div>

      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请选择生理周期" :visible.sync="physicycledialog">
          <rm-pop-common @change="physicyclechange" @cancel="physicycledialog=false;" datatype="seccode" kindno="physicycle" irrelevant="physicycleShowIrrelevant" key="physicycle"></rm-pop-common>
      </el-dialog>

      <!-- <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请选择标本类型" :visible.sync="specimendialog">
          <rm-pop-common @change="specimenchange" @cancel="specimendialog=false;" :multiple="true" datatype="specimen" irrelevant="specimenShowIrrelevant" key="specimen"></rm-pop-common>
      </el-dialog> -->
      <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请选择标本类型" :visible.sync="specimendialog" :destroy-on-close="true">
          <rm-SqlMultiple :leftOption="specoptionleft" :rightOption="specoptionright" @change="closespecimendialog"></rm-SqlMultiple>
      </el-dialog>
      <!--<el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请选择科室" :visible.sync="deptdialog">
          <rm-pop-common @change="deptchange" @cancel="deptdialog=false;" datatype="dept" irrelevant="deptShowIrrelevant" :multiple="true" key="dept"></rm-pop-common>
      </el-dialog>--->
      <!--科室多选弹窗 --->
      <el-dialog width="920px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请选择科室" :visible.sync="deptdialog" :destroy-on-close="true">
          <rm-SqlMultiple prono="LIS118" :leftOption="deptoption1" :rightOption="deptoption2" @change="closedeptdialog"></rm-SqlMultiple>
      </el-dialog>

           <!--科室专业类别多选弹窗 --->
      <el-dialog width="920px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请选择科室专业类别" :visible.sync="deptsubjectdialog" :destroy-on-close="true">
          <rm-SqlMultiple  :leftOption="subjectoption1" :rightOption="subjectoption2" @change="closedeptsubjectdialog"></rm-SqlMultiple>
      </el-dialog>

      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请选择医院" :visible.sync="hospdialog">
          <rm-pop-common @change="hospchange" @cancel="hospdialog=false;" datatype="hospital" :multiple="false" key="hospital"></rm-pop-common>
      </el-dialog>

      <!--与上次危机值比较-->
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="与上次危机值比较" :visible.sync="limitrules_dialogflag">
          <div>
              病人<el-input style="width:95px" v-model="limitrules_dialogflag_hours" oninput="value=value.replace(/[^\-?\d.]/g,'')"></el-input>
              小时内结果 <el-select v-model="limitrules_dialogflag_change" placeholder="请选择" style="width:100px">
                  <el-option key="+" label="升高" value="+"></el-option>
                  <el-option key="-" label="降低" value="-"></el-option>
                  <el-option key="" label="变化" selected value=""></el-option>
              </el-select>
              超过<el-input style="width:95px" v-model="limitrules_dialogflag_cg" oninput="value=value.replace(/[^\-?\d.]/g,'')"></el-input>
              ，百分比超过<el-input style="width:95px" v-model="limitrules_dialogflag_percent" oninput="value=value.replace(/[^\-?\d.]/g,'')"></el-input>%
          </div>
          <div align="right" style="width:100%;margin-top:10px;">
              <el-button @click="limitrules_dialogflag_saveevent" icon="el-icon-document">保存</el-button>
              <el-button @click="limitrules_dialogflag_cancelevent" icon="el-icon-close">取消</el-button>
          </div>
      </el-dialog>
      <!--上次比较危机值上报-->
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="上次比较危机值上报" :visible.sync="alertrules_dialogflag">
          <div>
              病人<el-input style="width:95px" v-model="alertrules_dialogflag_hours" oninput="value=value.replace(/[^\-?\d.]/g,'')"></el-input>
              小时内结果 <el-select v-model="alertrules_dialogflag_change" placeholder="请选择" style="width:100px">
                  <el-option key="+" label="升高" value="+"></el-option>
                  <el-option key="-" label="降低" value="-"></el-option>
                  <el-option key="" label="变化" selected value=""></el-option>
              </el-select>
              超过<el-input style="width:95px" v-model="alertrules_dialogflag_cg" oninput="value=value.replace(/[^\-?\d.]/g,'')"></el-input>
              ，百分比超过<el-input style="width:95px" v-model="alertrules_dialogflag_percent" oninput="value=value.replace(/[^\-?\d.]/g,'')"></el-input>%
          </div>
          <div align="right" style="width:100%;margin-top:10px;">
              <el-button @click="alertrules_dialogflag_saveevent" icon="el-icon-document">保存</el-button>
              <el-button @click="alertrules_dialogflag_cancelevent" icon="el-icon-close">取消</el-button>
          </div>
      </el-dialog>

      <!--危急值文字结果-->
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请填写危急值文字结果" :visible.sync="TxtResultListdialog" width="600px">
          <div style="height:300px">
              <div style="width:100%;float:left;height:30px">
                  <table style="width:100%;">
                      <tr>
                          <td>
                              <el-radio v-model="chkAsDanger" label="1">结果在取值列表中为危急值</el-radio>
                          </td>
                          <td>
                              <el-radio v-model="chkAsDanger" label="2">结果不在取值列表中为危急值</el-radio>
                          </td>
                      </tr>
                  </table>
              </div>
              <div style="width:100%;float:left;height:270px">
                  <vxe-table show-overflow ref="xTableDanger" height="auto" :data.sync="dangerTableData" show-header-overflow :edit-config="{trigger: 'click', mode: 'cell',showStatus:true,showIcon:false}" highlight-current-row highlight-hover-row resizable border size="mini" :mouse-config="{selected: true}">
                      <vxe-table-column type="index" title="NO." width="60" header-align="center">
                      </vxe-table-column>
                      <vxe-table-column field="txtresultlist" title="危急值文字结果" width="240" header-align="center" :edit-render="{name: 'input',autoselect:true}">
                      </vxe-table-column>
                      <vxe-table-column key="containtext" field="containtext" title="包含此文字即可" width="110px" align="center">
                                  <template v-slot="{ row }">
                                      <el-checkbox v-model="row.containtext" true-label="1" false-label="0"></el-checkbox>
                                  </template>
                              </vxe-table-column>
                  </vxe-table>
              </div>
          </div>
          <span slot="footer" class="dialog-footer">
              <el-button icon="el-icon-plus" @click="btnAdd('dg')">新增</el-button>
              <el-button icon="el-icon-delete" @click="btnDelete('dg')">删除</el-button>
              <el-button icon="el-icon-document" @click="btnSave('dg')">保存</el-button>
              <el-button icon="el-icon-close" @click="TxtResultListdialog=false">取消</el-button>
          </span>
      </el-dialog>

      <!--警示值文字结果-->
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="请填写警示值文字结果" :visible.sync="WarnResultListdialog">
          <div style="height:300px">
              <div style="width:100%;float:left;height:30px">
                  <table style="width:100%;">
                      <tr>
                          <td>
                              <el-radio v-model="chkAsWarn" label="1">结果在取值列表中为警示值</el-radio>
                          </td>
                          <td>
                              <el-radio v-model="chkAsWarn" label="2">结果不在取值列表中为警示值</el-radio>
                          </td>
                      </tr>
                  </table>
              </div>
              <div style="width:100%;float:left;height:270px">
                  <vxe-table show-overflow ref="xTableWarn" height="auto" :data.sync="warnTableData" show-header-overflow :edit-config="{trigger: 'click', mode: 'cell',showStatus:true,showIcon:false}" highlight-current-row highlight-hover-row resizable border size="mini" :mouse-config="{selected: true}">
                      <vxe-table-column type="index" title="NO." width="60" header-align="center">
                      </vxe-table-column>
                      <vxe-table-column field="warnresultlist" title="警示值文字结果" width="250" header-align="center" :edit-render="{name: 'input',autoselect:true}">
                      </vxe-table-column>
                  </vxe-table>
              </div>
          </div>
          <span slot="footer" class="dialog-footer">
              <el-button icon="el-icon-plus" @click="btnAdd('wn')">新增</el-button>
              <el-button icon="el-icon-delete" @click="btnDelete('wn')">删除</el-button>
              <el-button icon="el-icon-document" @click="btnSave('wn')">保存</el-button>
              <el-button icon="el-icon-close" @click="WarnResultListdialog=false">取消</el-button>
          </span>
      </el-dialog>

      <el-dialog v-el-drag-dialog :close-on-click-modal="false" title="复制" :visible.sync="CopyShow" v-if="CopyShow" width="500px">
          <table>
              <tr>
                  <td style="text-align:right">
                      当前报告单元:
                  </td>
                  <td>
                      <rm-ddl-rptunit prgno="LIS118" v-model="Qrptunitid" :appendtobody="true" width="200px" :defaultflag="'1'" :disabled="true"></rm-ddl-rptunit>
                  </td>
              </tr>
              <tr>
                  <td style="text-align:right">
                      请选择要复制到的报告单元:
                  </td>
                  <td>
                      <el-select v-model="rptunitidcopy" @dblclick.native="popMultipleChk(rptunitidcopy)" filterable clearable style="width:100%" placeholder="可双击开窗多选报告单元">
                          <el-option v-for="(item,index) in rptunitOption" :key="index" :value="item.data" :label="item.display"></el-option>
                      </el-select>
                      <!-- <rm-ddl-rptunit prgno="MNG139" v-model="rptunitidcopy" :appendtobody="true" width="200px" :defaultflag="'1'"></rm-ddl-rptunit> -->
                  </td>
              </tr>
          </table>
          <div style="text-align:right">
              <span class="dialog-footer" slot="footer">
                  <el-button @click="copyItem()">确 定</el-button>
                  <el-button @click="CopyShow=false">取 消</el-button>
              </span>
          </div>
      </el-dialog>

      <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="报告单元" :visible.sync="dialogMultipleVisible" :destroy-on-close="true">
          <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname" @change="closedialog"></rm-SqlMultiple>
      </el-dialog>

      <el-dialog width="600px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="复制消息" :visible.sync="dialogCopyMsgVisible" :destroy-on-close="true">
          <div v-for="(item,index) in copymsg" :key="index">{{ item }}</div>
          <div style="text-align:right">
              <span class="dialog-footer" slot="footer">
                  <el-button @click="dialogCopyMsgVisible = false, copymsg = []">确 定</el-button>
              </span>
          </div>
      </el-dialog>

      <!--病人年龄-->
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="病人年龄" ref="dialogage" :visible.sync="diaglogageVisible" width="450px">
          <table class="table1style">
              <tr>
                  <td>
                      <el-input v-model="age.agenum1" type="number" style="width:80px" @change="getAgestr" @focus="ageFocus($event)" ref="refagenum1"></el-input>
                  </td>
                  <td>
                      <el-radio-group v-model="age.ageunit1">
                          <el-radio :label="'Y'" @change="agenum1Change('Y')">岁</el-radio>
                          <el-radio :label="'M'" @change="agenum1Change('M')">月</el-radio>
                          <el-radio :label="'D'" @change="agenum1Change('D')">天</el-radio>
                          <!-- <el-radio :label="'H'" @change="agenum1Change('H')">小时</el-radio>
                          <el-radio :label="'F'" @change="agenum1Change('F')">分钟</el-radio> -->
                      </el-radio-group>
                  </td>
              </tr>
              <!-- <tr>
                  <td>
                      <el-input v-model="age.agenum2" type="number" style="width:80px" @change="getAgestr" @focus="ageFocus($event)"></el-input>
                  </td>
                  <td>
                      <el-radio-group v-model="age.ageunit2" disabled>
                          <el-radio :label="'Y'">岁</el-radio>
                          <el-radio :label="'M'">月</el-radio>
                          <el-radio :label="'D'">天</el-radio>
                          <el-radio :label="'H'">小时</el-radio>
                          <el-radio :label="'F'">分钟</el-radio>
                      </el-radio-group>
                  </td>
              </tr> -->
          </table>
          <div style="color:rgb(68 170 246);margin:5px">
              返回年龄：{{age.agemodel}}<br>
              可在前台病人年龄框中输入：{{age.agestr}}返回相同结果
          </div>
          <span slot="footer" class="dialog-footer">
              <el-button type="primary" @click.native="$refs.dialogage.Confirm()">确 定</el-button>
              <el-button @click.native="$refs.dialogage.Cancel()">取 消</el-button>
          </span>
      </el-dialog>
      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="提示" :visible.sync="remindVisible" width="550px">
          <div style="height: 160px">
              <span style="font-size: 16px;color:blue;">该报告单元不存在项目危急值参数，如果要添加，请进行以下操作：<br/>1.点击项目危急值参数右侧的【显示所有工作组】(如果已有跳过此步)<br/>2.点击该报告单元对应工作组名称右侧的【显示所有报告单元】;<br/> 3.自动显示该报告单元的所有报告项目(无需再点【显示所有报告项目】);<br/>4.选择报告项目后点击页面右上角的【新增】;<br/>5.设置好危急值参数后点击【保存】<br/><br/>*报告单元和报告项目可输入代码或名称进行快速定位</span>
          </div>
          <span slot="footer" class="dialog-footer">
              <el-checkbox v-model="noremindflag" style="font-size: 12px; margin-right:30px;">本次打开不再提醒</el-checkbox>
              <el-button @click="remindVisible = false">确定</el-button>
          </span>
      </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
  name: "LIS118",
  data() {
      return {
          itemOptions: [],
          rptitemcode: "",
          rptitemname: "",
          itemcodeen: "",
          sexOptions: [
              { label: "男", value: "1" },
              { label: "女", value: "2" },
              { label: "无关", value: "All" },
          ],
          specimenOptions: [],
          deptOptions: [],
          specOptions: [],
          loading: false,
          Formdialog: false,
          okFirstLoading: false,
          physicycledialog: false,
          specimendialog: false,
         deptdialog:false,

          hospdialog: false,
          dialogtitle: "",
          Trptunitid: "",
          tempindex: 0,
          actionindex: 0,
          tableData: [],
          limitrules_dialogflag: false,
          limitrules_dialogflag_hours: "",
          limitrules_dialogflag_change: "",
          limitrules_dialogflag_cg: "",
          limitrules_dialogflag_percent: "",
          alertrules_dialogflag: false,
          alertrules_dialogflag_hours: "",
          alertrules_dialogflag_change: "",
          alertrules_dialogflag_cg: "",
          alertrules_dialogflag_percent: "",
          WarnResultListdialog: false,
          TxtResultListdialog: false,
          diaglogageVisible: false,
          age: {
              agenum1: "",
              agenum2: "",
              ageunit1: "M",
              ageunit2: "D",
              agestr: "",
              agemodel: "",
          },
          dangerTableData: [],
          warnTableData: [],
          chkAsDanger: "1",
          chkAsWarn: "1",
          keyConfig: {
              isArrow: true,
              isDel: true,
              isTab: true,
              isEdit: true,
          },
          ruleForm: {
              rptunitid: "",
              rpt_itemcode: "",
              patsex: "",
              physicycle: "",
              ageyear1: "",
              ageyear2: "",
              specimen_code: "",
              deptno: "",
              deptsubject: "",
              diag_icd: "",
              seq: "",
              limit_l: "",
              limit_h: "",
              warn_l: "",
              warn_h: "",
              limit_rule: "",
              txtresultlist: "",
              containtext:"0",
              onlyfirst: "0",
              alert_rule: "",
              resetbypatwardflag: "0",
          },
          QFormdata: {
              rptunitid: "",
              rpt_itemcode: "",
              patsex: "",
              physicycle: "",
              ageyear1: "",
              ageyear2: "",
              specimen_code: "",
              deptno: "",
              deptsubject: "",
              diag_icd: "",
          },
          perEditflag: false,
          Qrptunitid: "",
          Qrptunitname: "",

          CopyShow: false,
          rptunitidcopy: 0,
          option1: [],
          option2: [],
          fieldname: "rptunitid",
          dialogMultipleVisible: false,

          copymsg: [],
          dialogCopyMsgVisible: false,

          deptoption1: [],
          deptoption2: [],

          specoptionleft:[],
          specoptionright:[],

          // 科室专业类别多选弹窗
          deptsubjectOptions:[],
          deptsubjectdialog: false,
          subjectoption1: [],
          subjectoption2: [],
          props: {
              label: "name",
              children: "children",
              isLeaf: "leaf",
          },
          defaultExpandKeys: [0],
          nodeKey: "",
          showButton: false,
          currentid: 0,
          showall: "0",
          replaceItemOption: false,
          RptItemData: [],
          labgrouprptunit: [],
          expandGroup: [],
          remindVisible: false,
          noremindflag: false,
          defaultRptitemOption: [],
      };
  },
  watch:{
      nodeKey(val) {
          if (val) {
              this.$nextTick(() => {
                  this.$refs.treenodes.setCurrentKey(val);
                  this.$nextTick(() => {
                      if(document.querySelector(".is-current")) {
                          document.querySelector(".is-current").firstChild.click();
                      }
                  });
              });
          }
      },
      Qrptunitid(val) {
          //报告单元ID有值，用对应的报告项目
          if (val) {
              if(this.replaceItemOption) this.refreshRptitemOption(val);
          } else {
              this.itemOptions = this.defaultRptitemOption;
          }
      },
  },
  created() {
      this.defaultExpandKeys = [-9999];
      this.getOption();
      //this.InitPageData(); //初始化主列表
  },
  mounted() {},
  updated() {
      if (this.okFirstLoading) {
          let currentrow = (currentrow = this.$refs.xTable.getData(0));
          this.$nextTick(() => {
              if (currentrow) {
                  this.okFirstLoading = false;
                  this.$refs.xTable.setCurrentRow(currentrow);
                  this.curselectrow = currentrow;
              }
          });
      }
  },
  methods: {
      async loadNode(node, resolve) {
          if (node.level === 0) {
              this.resolve_had = resolve;
              var data = await this.treelist(node.level, 0);
              return resolve([
                  {
                      name: "项目危急值参数",
                      id: 0,
                      leaf: false,
                      isall: false,
                      nodeid: -9999,
                  },
              ]);
          } else if (node.level > 3) {
              return resolve([]);
          } else {
              //工作组查询的时候去掉g_
              let realnodeid = node.level == 2 ? node.data.nodeid.replace("g_", "") : node.data.nodeid;
              var data = await this.treelist(node.level, realnodeid);
              if (data.length == 0) node.leaf = true;
              if (data.length > 0 && node.level > 1) node.data.name = "[" + (node.level == 4 ? node.data.enname : realnodeid) + "]" + node.data.na + "  (" + data.length + ")";
              return resolve(data);
          }
      },
      async treelist(level, nodeid) {
          try {
              let tm = [];
              const response = await this.$tool.request({
                  url: "LIS/LIS1/LIS118",
                  method: "post",
                  data: {
                      action: "gettreelist",
                      nodeid: nodeid,
                      level: level,
                      showall: this.showall,
                  },
              });
              this.showall = "0";
              if (response.Data) {
                  response.Data.forEach((element) => {
                      let node = {};
                      //是否显示了所有子项
                      node.isall = false;
                      if (level > 0) {
                          node.na = element.cp_treetext;
                          if (level == 3){
                              node.name = "[" + element.cp_treeen + "]" + element.cp_treetext + "  (" + element.cp_treecnt + ")";
                              node.enname = element.cp_treeen;
                          }
                          else node.name = "[" + element.cp_treedata + "]" + element.cp_treetext + "  (" + element.cp_treecnt + ")";
                          // 为了防止工作组ID和报告单元ID值相同的情况，这里工作组ID前面加个g_
                          if (level == 1) {
                              node.nodeid = "g_" + element.cp_treedata;
                          } else {
                              node.nodeid = element.cp_treedata;
                              if(level == 2 && element.cp_treecnt == 0) this.labgrouprptunit.push({ labgroupid: nodeid, rptunitid: element.cp_treedata });
                          }
                          if (level > 3) node.leaf = true; //第3层无下级节点
                          tm.push(node);
                      }
                  });
              }
              return tm;
          } catch (e) {
              console.log(e);
          }
      },
      refreshTreeNode(node, showall) {
          if (node) {
              //根节点刷新，已展开工作组清空
              if(node.level == 1) this.expandGroup = [];
              //是否以显示所有刷新子节点
              this.showall = showall ? "1" : "0";
              node.loaded = false
              node.expand() // 主动调用展开节点方法，重新查询该节点下的所有子节点
          }
      },
      //切换动作
      tree_checkchange_event(data, node, key) {
          this.resetData().then(() => {
              //报告项目
              if (node.level == 4) {
                  var rptcode = data.nodeid;
                  var rptname = data.na;
                  var rptnameen = data.enname;
                  var qcnode = this.$refs.treenodes.getNode(node.parent);
                  var rptunitid = qcnode.data.nodeid;
                  var rptunitname = qcnode.data.na;
                  this.queryData(rptunitid, rptcode, rptname, rptunitname, rptnameen);
              } else if (node.level == 3) { // 报告单元
                  this.Qrptunitid = data.nodeid;
                  this.Qrptunitname = data.na;
                  this.rptitemcode = "";
                  this.rptitemname = "";
                  this.itemcodeen = "";
                  this.InitPageData();
              } else if (node.level == 2) { // 工作组
                  this.Qrptunitid = "";
                  this.Qrptunitname = "";
                  this.rptitemcode = "";
                  this.rptitemname = "";
                  this.itemcodeen = "";
              }
          });
      },
      //展开动作
      tree_expand(data, node, key) {
          // 工作组
          if(node.level == 2) {
              this.expandGroup.push(data.nodeid);
          }
      },
      //关闭动作
      tree_collapse(data, node, key) {
          // 工作组
          if(node.level == 2) {
              this.expandGroup.splice(this.expandGroup.indexOf(data.nodeid), 1)
          }
      },
      //初始化数据
      resetData() {
          return new Promise((s, f) => {
              this.tableData = [];
              s();
          });
      },
      treeenter(node) {
          this.currentid = node.id;
          this.showButton = true;
      },
      treeleave(node) {
          this.currentid = node.id;
          this.showButton = false;
      },
      ShowAllGroup(node) {
          node.isall = !node.isall;
          node.childNodes = [];
          this.refreshTreeNode(node, node.isall);
      },
      ShowAllRptunit(node) {
          node.isall = !node.isall;
          node.childNodes = [];
          this.refreshTreeNode(node, node.isall);
          //如果已经选中了报告单元，那么直接加载所有报告项目
          if(this.Qrptunitid)
          {
              setTimeout(() => {
                  var node = this.$refs.treenodes.getNode(this.Qrptunitid);
                  this.ShowAllRptitem(node);
                  this.nodeKey = this.Qrptunitid;
              },100);
          }
      },
      ShowAllRptitem(node) {
          node.isall = !node.isall;
          this.replaceItemOption = true;
          node.childNodes = [];
          this.refreshTreeNode(node, node.isall);
          if(this.Qrptunitid) this.refreshRptitemOption(this.Qrptunitid);
      },
      refreshRptitemOption(rptunitid) {
          this.$tool
              .request({
                  url: "LIS/LIS1/LIS118",
                  method: "post",
                  data: {
                      action: "getrptunititem",
                      rptunitid: rptunitid,
                  },
              })
              .then((res) => {
                  this.itemOptions = res.itemOptions;
              })
              .catch((e) => {
                  console.log("error", e);
              });
      },
      //左边tree行变换行
      queryData(rptunitid, rptcode, rptname, rptunitname, rptnameen) {
          this.Qrptunitid = rptunitid;
          this.Qrptunitname = rptunitname;
          this.rptitemcode = rptcode;
          this.rptitemname = rptname;
          this.itemcodeen = rptnameen;
          this.InitPageData();
      },
      limitrules_dialogflag_cancelevent() {
          this.limitrules_dialogflag = false;
          this.limitrules_dialogflag_hours = "";
          this.limitrules_dialogflag_change = "";
          this.limitrules_dialogflag_cg = "";
          this.limitrules_dialogflag_percent = "";
      },
      limitrules_dialogflag_saveevent() {
          this.curselectrow.limit_rule = this.limitrules_dialogflag_hours + "|" + this.limitrules_dialogflag_change + this.limitrules_dialogflag_cg + "|" + this.limitrules_dialogflag_percent;
          this.limitrules_dialogflag_cancelevent();
      },
      alertrules_dialogflag_cancelevent() {
          this.alertrules_dialogflag = false;
          this.alertrules_dialogflag_hours = "";
          this.alertrules_dialogflag_change = "";
          this.alertrules_dialogflag_cg = "";
          this.alertrules_dialogflag_percent = "";
      },
      alertrules_dialogflag_saveevent() {
          this.curselectrow.alert_rule = this.alertrules_dialogflag_hours + "|" + this.alertrules_dialogflag_change + this.alertrules_dialogflag_cg + "|" + this.alertrules_dialogflag_percent;
          this.alertrules_dialogflag_cancelevent();
      },
      btnAdd(key) {
          if (key == "dg") {
              this.$refs.xTableDanger.insert().then(({ row }) => {
                  this.$refs.xTableDanger.setCurrentRow(row);
                  this.$refs.xTableDanger.setActiveRow(row);
              });
          } else {
              this.$refs.xTableWarn.insert().then(({ row }) => {
                  this.$refs.xTableWarn.setCurrentRow(row);
                  this.$refs.xTableWarn.setActiveRow(row);
              });
          }
      },
      btnDelete(key) {
          try {
              if (key == "dg") {
                  var delrow = this.$refs.xTableDanger.getCurrentRow();
                  if (delrow) {
                      var alld = this.$refs.xTableDanger.tableData;
                      var rowindex = alld.indexOf(delrow);
                      this.$refs.xTableDanger.remove(delrow);
                      let havedata = this.$refs.xTableDanger.tableData;
                      if (havedata.length > 0) {
                          if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                          let selectrow = havedata[rowindex];
                          this.$refs.xTableDanger.setCurrentRow(selectrow);
                      }
                  }
              } else {
                  var delrow = this.$refs.xTableWarn.getCurrentRow();
                  if (delrow) {
                      var alld = this.$refs.xTableWarn.tableData;
                      var rowindex = alld.indexOf(delrow);
                      this.$refs.xTableWarn.remove(delrow);
                      let havedata = this.$refs.xTableWarn.tableData;
                      if (havedata.length > 0) {
                          if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                          let selectrow = havedata[rowindex];
                          this.$refs.xTableWarn.setCurrentRow(selectrow);
                      }
                  }
              }
          } catch (e) {
              console.log("error", e);
          }
      },
      btnSave(key) {
          let tempstr = "";
          let data = [];
          if (key == "dg") {
              //危急值
              data = this.$refs.xTableDanger.tableData;
              if (data.length > 0) {
                  data.forEach((item) => {
                      if (!!item.txtresultlist) {
                          if(item.containtext){
                              tempstr += item.txtresultlist +"#*#" +item.containtext+ ",";
                          }
                          else{
                              tempstr += item.txtresultlist +"#*#" +"0"+ ",";
                          }

                      }
                  });
                  if (!!tempstr) {
                      tempstr = tempstr.substring(0, tempstr.length - 1);
                      if (this.chkAsDanger == "1") {
                          this.curselectrow.txtresultlist = tempstr;
                      } else {
                          this.curselectrow.txtresultlist = "-" + tempstr;
                      }
                  } else {
                      this.curselectrow.txtresultlist = "";
                  }
              } else {
                  this.curselectrow.txtresultlist = "";
              }
              this.TxtResultListdialog = false;
          } else {
              //警示值
              data = this.$refs.xTableWarn.tableData;
              if (data.length > 0) {
                  data.forEach((item) => {
                      if (!!item.warnresultlist) {
                          tempstr += item.warnresultlist + ",";
                      }
                  });
                  if (!!tempstr) {
                      tempstr = tempstr.substring(0, tempstr.length - 1);
                      if (this.chkAsWarn == "1") {
                          this.curselectrow.warnresultlist = tempstr;
                      } else {
                          this.curselectrow.warnresultlist = "-" + tempstr;
                      }
                  } else {
                      this.curselectrow.warnresultlist = "";
                  }
              } else {
                  this.curselectrow.warnresultlist = "";
              }
              this.WarnResultListdialog = false;
          }
      },
      QrptitemChange(code) {
          this.rptitemcode = code;
          let rptitem = this.itemOptions.find((m) => m.value == code);
          if(rptitem){
              this.rptitemname = rptitem.label;
              this.itemcodeen = rptitem.nameen;
          }
          //只有当有报告单元且报告项目自身有值才跳转
          if(this.Qrptunitid && code) this.nodeKey = code;
          this.InitPageData();
      },
      QrptunitChange(code, name) {
          this.Qrptunitid = code;
          this.Qrptunitname = name;
          this.Trptunitid = code;
          if (code) {
              let labgroup = this.labgrouprptunit.find((item)=> item.rptunitid == code);
              //先找到工作组再找报告单元
              if(labgroup)
              {
                  let labgroupid = "g_" + labgroup.labgroupid;
                  //如果已展开那么直接跳转报告单元
                  if(this.expandGroup.indexOf(labgroupid) > -1) {
                      this.nodeKey = code;
                  } else { //未展开则要先展开工作组再展开报告单元
                      this.nodeKey = labgroupid;
                      //加载需要时间，延时100ms
                      setTimeout(() => { this.nodeKey = code; },100);
                  }
              } else {
                  this.tableData = [];
                  if(!this.noremindflag) this.remindVisible = true;
              }
          } else {
              this.InitPageData();
          }
      },
      formatterFun({ column, cellValue }) {
          let fieldArr = ["patsex", "specimen_name", "deptname", "deptsubjectname","diag_icd", "physicyclename", "hospname"];
          let fieldAge = ["ageyear1", "ageyear2"];
          if (fieldArr.includes(column.property)) {
              if (cellValue == "All") {
                  return "无关";
              } else {
                  return cellValue;
              }
          } else {
              return cellValue;
          }
      },
      physicyclechange(code, name) {
          this.curselectrow.physicycle = code;
          this.curselectrow.physicyclename = name;
          this.physicycledialog = false;
      },
      specimenchange(code, name) {
          if (!!name) {
              //这种模式目前不存在
              this.curselectrow.deptno = code;
              this.curselectrow.deptname = name;
          } else {
              let datacode = "";
              let dataname = "";
              let fdata = code.find((m) => m.hidkey == "All"); //只要勾选了无关，如果还有其他数据，只存为无关
              if (!!fdata) {
                  datacode = "All";
                  dataname = "无关";
              } else {
                  code.forEach((item) => {
                      if (datacode == "") {
                          datacode = item.hidkey;
                          dataname = item.hidname;
                      } else {
                          datacode += "," + item.hidkey;
                          dataname += "," + item.hidname;
                      }
                  });
              }
              this.curselectrow.specimen_code = datacode;
              this.curselectrow.specimen_name = dataname;
          }
          this.specimendialog = false;
      },
      deptchange(code, name) {
          if (!!name) {
              //这种模式目前不存在
              this.curselectrow.deptno = code;
              this.curselectrow.deptname = name;
          } else {
              let datacode = "";
              let dataname = "";
              let fdata = code.find((m) => m.hidkey == "All"); //只要勾选了无关，如果还有其他数据，只存为无关
              if (!!fdata) {
                  datacode = "All";
                  dataname = "无关";
              } else {
                  code.forEach((item) => {
                      if (datacode == "") {
                          datacode = item.hidkey;
                          dataname = item.hidname;
                      } else {
                          datacode += "," + item.hidkey;
                          dataname += "," + item.hidname;
                      }
                  });
              }
              this.curselectrow.deptno = datacode;
              this.curselectrow.deptname = dataname;
          }
          this.deptdialog = false;
      },
      hospchange(code, name) {
          if (!!name) {
              //这种模式目前不存在
              this.curselectrow.hospcode = code;
              this.curselectrow.hospname = name;
          } else {
              let datacode = "";
              let dataname = "";
              let fdata = code.find((m) => m.hidkey == "All"); //只要勾选了无关，如果还有其他数据，只存为无关
              if (!!fdata) {
                  datacode = "All";
                  dataname = "无关";
              } else {
                  code.forEach((item) => {
                      if (datacode == "") {
                          datacode = item.hidkey;
                          dataname = item.hidname;
                      } else {
                          datacode += "," + item.hidkey;
                          dataname += "," + item.hidname;
                      }
                  });
              }
              this.curselectrow.hospcode = datacode;
              this.curselectrow.hospname = dataname;
          }
          this.hospdialog = false;
      },
      getOption() {
          this.$tool
              .request({
                  url: "LIS/LIS1/LIS118",
                  method: "post",
                  data: {
                      action: "getOption",
                  },
              })
              .then((res) => {
                  this.itemOptions = res.Data;
                  this.defaultRptitemOption = res.Data;
                  this.rptunitOption = res.rptunitOption;
                  this.deptOptions = res.deptOptions;
                  this.specOptions = res.specOptions;
                  this.deptsubjectOptions = res.deptsubjectOptions;
                  this.labgrouprptunit = res.labgrouprptunit;
              })
              .catch((e) => {
                  console.log("error", e);
              });
      },
      InitPageData() {
          this.tempindex = 0;
          this.tableData = [];
          this.loading = true;
          this.$tool
              .request({
                  url: "LIS/LIS1/LIS118",
                  method: "post",
                  data: {
                      action: "query",
                      rptunitid: this.Qrptunitid,
                      rptitemcode: this.rptitemcode,
                  },
              })
              .then((response) => {
                  this.tableData = response.Data;
                  this.loading = false;
                  this.okFirstLoading = true;
                  if(this.Qrptunitid && this.rptitemcode) {
                      var node = this.$refs.treenodes.currentNode.node;
                      if(node && node.level == 4) node.data.name = "[" + node.data.enname + "]" + node.data.na + "  (" + this.tableData.length + ")";
                  }
              })
              .catch((e) => {
                  this.loading = false;
                  console.log("error", e);
              });
      },
      initialFormList() {
          this.loading = true;
          this.$tool
              .request({
                  url: "LIS/LIS1/LIS118",
                  method: "post",
                  data: {
                      action: "initialFormList",
                      qInfo: this.QFormdata,
                  },
              })
              .then((response) => {
                  this.QFormdata = response.Data;
                  this.loading = false;
              })
              .catch((e) => {
                  this.loading = false;
                  console.log("error", e);
              });
      }, //主列表行选中
      currentChangeEvent({ row, $rowIndex }) {
          this.tempindex = $rowIndex;
          this.actionindex = 2; //修改
          this.Trptunitid = row.rptunitid;
          this.curselectrow = row;
          this.QFormdata = {
              rptunitid: row.rptunitid,
              rpt_itemcode: row.rpt_itemcode,
              patsex: row.patsex,
              physicycle: row.physicycle,
              ageyear1: row.ageyear1,
              ageyear2: row.ageyear2,
              specimen_code: row.specimen_code,
              deptno: row.deptno,
              deptsubject: row.deptsubject,
              diag_icd: row.diag_icd,
          };
      },
      cellactiveMethod({ row, column, cellValue }) {
          //"rptunitname",
          let columnArr = ["physicyclename", "specimen_name", "deptname","deptsubjectname", "rpt_itemname", "limit_rule", "hospname"];
          if (columnArr.includes(column.property)) {
              return false;
          } else {
              return true;
          }
      },
      rowClassName({ row, rowIndex }) {
          let isDirty = this.$refs.xTable.hasRowChange(row);
          if (isDirty) {
              return "row-modify";
          }
          if (this.$refs.xTable.hasRowInsert(row)) return "row-new";
      },
      opendialog({ row, column }) {
          if (column.property == "physicyclename") {
              this.physicycledialog = true;
          } else if (column.property == "specimen_name") {
              this.curselectrow = row;
              let temp=XEUtils.clone(this.specOptions,true);
              this.specoptionleft = [];
              this.specoptionright = [];
              if(!!row.specimen_name){
                  let codes=row.specimen_code.split(",");
                  codes.forEach((item)=>{
                      let rdata = temp.find((m) => m.data==item);
                      if(rdata != undefined && rdata != null){
                          this.specoptionright.push(rdata);
                      }
                  })
                  temp.forEach((item) => {
                      if(codes.indexOf(item.data + "")<0){
                          this.specoptionleft.push(item);
                      }
                  })
              }else{
                  this.specoptionleft = temp ;
              }
              this.specimendialog = true;
          } else if (column.property == "deptname") {
              // this.deptdialog = true;
              this.curselectrow = row;
              let temp = XEUtils.clone(this.deptOptions, true);
              this.deptoption1 = [];
              this.deptoption2 = [];
              if (!!row.deptname) {
                  let k = row.deptno.split(",");
                  k.forEach((item) => {
                      let ndata = temp.find((m) => m.data == item);
                      if (ndata != undefined && ndata != null) {
                          this.deptoption2.push(ndata);
                      }
                  });
                  temp.forEach((item) => {
                      if (k.indexOf(item.data + "") < 0) {
                          this.deptoption1.push(item);
                      }
                  });
              } else {
                  this.deptoption1 = temp;
              }
              this.deptdialog = true;
          }else if (column.property == "deptsubjectname") {
              // this.deptdialog = true;
              this.curselectrow = row;
              let temp = XEUtils.clone(this.deptsubjectOptions, true);
              this.subjectoption1 = [];
              this.subjectoption2 = [];
              if (!!row.deptsubject) {
                  let k = row.deptsubject.split(",");
                  k.forEach((item) => {
                      let ndata = temp.find((m) => m.data == item);
                      if (ndata != undefined && ndata != null) {
                          this.subjectoption2.push(ndata);
                      }
                  });
                  temp.forEach((item) => {
                      if (k.indexOf(item.data + "") < 0) {
                          this.subjectoption1.push(item);
                      }
                  });
              } else {
                  this.subjectoption1 = temp;
              }
              this.deptsubjectdialog = true;
          } else if (column.property == "hospname") {
              this.hospdialog = true;
          } else if (column.property == "limit_rule") {
              this.limitrules_dialogflag = true;
              let limitruleslist = this.curselectrow.limit_rule.split("|");
              if (limitruleslist.length == 3) {
                  if (limitruleslist[0] != "") {
                      this.limitrules_dialogflag_hours = limitruleslist[0];
                  }
                  if (limitruleslist[1] != "") {
                      if (limitruleslist[1].substring(0, 1)) {
                          this.limitrules_dialogflag_change = "+";
                          this.limitrules_dialogflag_cg = limitruleslist[1].substring(1);
                      } else if (limitruleslist[1].substring(0, 1)) {
                          this.limitrules_dialogflag_change = "-";
                          this.limitrules_dialogflag_cg = limitruleslist[1].substring(1);
                      } else {
                          this.limitrules_dialogflag_change = "";
                          this.limitrules_dialogflag_cg = limitruleslist[1];
                      }
                  }
                  if (limitruleslist[2] != "") {
                      this.limitrules_dialogflag_percent = limitruleslist[2];
                  }
              } else {
                  this.limitrules_dialogflag_hours = "";
                  this.limitrules_dialogflag_change = "";
                  this.limitrules_dialogflag_cg = "";
                  this.limitrules_dialogflag_percent = "";
              }
          } else if (column.property == "alert_rule") {
              this.alertrules_dialogflag = true;
              let alertruleslist = this.curselectrow.alert_rule.split("|");
              if (alertruleslist.length == 3) {
                  if (alertruleslist[0] != "") {
                      this.alertrules_dialogflag_hours = alertruleslist[0];
                  }
                  if (alertruleslist[1] != "") {
                      if (alertruleslist[1].substring(0, 1)) {
                          this.alertrules_dialogflag_change = "+";
                          this.alertrules_dialogflag_cg = alertruleslist[1].substring(1);
                      } else if (alertruleslist[1].substring(0, 1)) {
                          this.alertrules_dialogflag_change = "-";
                          this.alertrules_dialogflag_cg = alertruleslist[1].substring(1);
                      } else {
                          this.alertrules_dialogflag_change = "";
                          this.alertrules_dialogflag_cg = alertruleslist[1];
                      }
                  }
                  if (alertruleslist[2] != "") {
                      this.alertrules_dialogflag_percent = alertruleslist[2];
                  }
              } else {
                  this.alertrules_dialogflag_hours = "";
                  this.alertrules_dialogflag_change = "";
                  this.alertrules_dialogflag_cg = "";
                  this.alertrules_dialogflag_percent = "";
              }
          } else if (column.property == "warnresultlist") {
              this.WarnResultListdialog = true;
              this.warnTableData = [];
              let warnresultlist = this.curselectrow.warnresultlist == null ? "" : this.curselectrow.warnresultlist; //去除indexof不能检测的null
              if (warnresultlist != "") {
                  if (warnresultlist.indexOf("-") == 0) {
                      warnresultlist = warnresultlist.substring(1, warnresultlist.length);
                      this.chkAsWarn = "2";
                  } else {
                      this.chkAsWarn = "1";
                  }
                  if (warnresultlist.length > 0) {
                      let wntmparr = warnresultlist.split(",");
                      wntmparr.forEach((item, index) => {
                          this.warnTableData.push({ _XID: index, warnresultlist: item });
                      });
                  }
              } else {
                  this.chkAsWarn = "1";
                  this.warnTableData = [];
              }
          } else if (column.property == "txtresultlist") {
              this.TxtResultListdialog = true;
              this.dangerTableData = [];
              let txtresultlist = this.curselectrow.txtresultlist == null ? "" : this.curselectrow.txtresultlist; //去除indexof不能检测的null
              if (txtresultlist != "") {
                  if (txtresultlist.indexOf("-") == 0) {
                      txtresultlist = txtresultlist.substring(1, txtresultlist.length);
                      this.chkAsDanger = "2";
                  } else {
                      this.chkAsDanger = "1";
                  }
                  if (txtresultlist.length > 0) {
                      let dgtmparr = txtresultlist.split(",");
                      dgtmparr.forEach((item, index) => {
                          var itemstr = item.split("#*#");
                          this.dangerTableData.push({ _XID: index, txtresultlist: itemstr[0],containtext: itemstr[1]});
                      });
                  }
              } else {
                  this.chkAsDanger = "1";
                  this.dangerTableData = [];
              }
          } else if (["ageyear1", "ageyear2"].includes(column.property)) {
              this.age.agenum1 = "";
              this.age.agenum2 = "";
              this.age.ageunit1 = "M";
              this.age.ageunit2 = "D";
              this.age.agestr = "";
              this.age.agemodel = "";
              setTimeout(() => {
                  this.$refs.refagenum1.focus();
              }, 10);
              this.ageShowDialog(row, column);
          } else {
          }
      },
      closedeptdialog(value, name, label) {
          if (value != "close") {
              if (value.indexOf("All") > -1) {
                  //若选中的数据包含无关则值为无关
                  this.curselectrow.deptno = "All";
                  this.curselectrow.deptname = "无关";
              } else {
                  this.curselectrow.deptno = value;
                  this.curselectrow.deptname = label;
              }
          }
          this.deptdialog = false;
      },


      closedeptsubjectdialog(value, name, label) {
          if (value != "close") {
              if (value.indexOf("All") > -1) {
                  //若选中的数据包含无关则值为无关
                  this.curselectrow.deptsubject = "All";
                  this.curselectrow.deptsubjectname = "无关";
              } else {
                  this.curselectrow.deptsubject = value;
                  this.curselectrow.deptsubjectname = label;
              }
          }
          this.deptsubjectdialog = false;
      },

      closespecimendialog(value, name, label){
          debugger;
          if (value != "close") {
              if (value.indexOf("All") > -1) {
                  //若选中的数据包含无关则值为无关
                  this.curselectrow.specimen_code = "All";
                  this.curselectrow.specimen_name = "无关";
              } else {
                  this.curselectrow.specimen_code = value;
                  this.curselectrow.specimen_name = label;
              }
          }
          this.specimendialog = false;
      },
      //年龄相关
      ageFocus(event) {
          event.currentTarget.select();
      },
      agenum1Change(flag) {
          switch (flag) {
              case "Y":
                  this.age.ageunit2 = "M";
                  break;
              case "M":
                  this.age.ageunit2 = "D";
                  break;
              case "D":
                  this.age.ageunit2 = "H";
                  break;
              case "H":
                  this.age.ageunit2 = "F";
                  break;
              default:
                  this.age.ageunit2 = "F";
          }
          this.getAgestr();
      },
      editChange({ row, column }) {
          if (column.property == "ageyear1") {
              if (!!row.ageyear1 && Number(row.ageyear1) != -1) {
                  this.GetPatBirthAge(row.ageyear1)
                      .then((res) => {
                          row.ageyear1 = res.str;
                          row.agestr1 = res.str1;
                          //  row.ageyear1str = res.Item1.replace("y","岁");
                      })
                      .catch((e) => {
                          // row.ageyear1 = "-1";
                      });
              } else {
                  row.ageyear1 = "-1";
              }
          } else if (column.property == "ageyear2") {
              if (!!row.ageyear2 && Number(row.ageyear2) != -1) {
                  this.GetPatBirthAge(row.ageyear2)
                      .then((res) => {
                          row.ageyear2 = res.str;
                          row.agestr2 = res.str1;
                      })
                      .catch((e) => {
                          // row.ageyear2 = "-1";
                      });
              } else {
                  row.ageyear2 = "-1";
              }
          }
      },
      ageShowDialog(row, column) {
          this.$refs.dialogage
              .ShowDialog()
              .then(() => {
                  if (this.age.agenum1 == "") {
                      this.ageShowDialog(row, column);
                      this.$alert("请输入一级年龄！", "提示");
                      return false;
                  }

                  if (column.property == "ageyear1") {
                      if (!!this.age.agenum1 && Number(this.age.agenum1) != -1) {
                          this.getAgestr();
                          this.GetPatBirthAge(this.age.agestr)
                              .then((res) => {
                                  row.ageyear1 = res.str;
                                  row.agestr1 = res.str1;
                              })
                              .catch((e) => {
                                  //row.ageyear1 = "-1";
                              });
                      } else {
                          //row.ageyear1 = "-1";
                      }
                  } else if (column.property == "ageyear2") {
                      if (!!this.age.agenum1 && Number(this.age.agenum1) != -1) {
                          this.getAgestr();
                          this.GetPatBirthAge(this.age.agestr)
                              .then((res) => {
                                  row.ageyear2 = res.str;
                                  row.agestr2 = res.str1;
                              })
                              .catch((e) => {
                                  // row.ageyear2 = "-1";
                              });
                      } else {
                          //row.ageyear2 = "-1";
                      }
                  }
              })
              .catch(() => {
                  console.log("catch");
              });
      },
      getAgestr() {
          if (this.age.ageunit1 != this.age.ageunit2) {
              if (this.age.agenum1 != "") {
                  this.age.agestr = this.age.agenum1 + this.age.ageunit1;
              }
              if (this.age.agenum2 != "") {
                  this.age.agestr += this.age.agenum2 + this.age.ageunit2;
              }
          } else {
              if (this.age.agenum1 != "") this.age.agestr = this.age.agenum1 + this.age.ageunit1;
              this.age.agenum2 = "";
          }
          this.age.agestr = this.age.agestr.toLowerCase();
          if (this.age.agestr != "") this.age.agemodel = this.age.agestr.toLowerCase().replace("y", "岁").replace("m", "月").replace("d", "天").replace("h", "小时").replace("f", "分钟");
      },
      GetPatBirthAge(agestr) {
          return this.$tool.request({
              url: "ucent/liscomm",
              method: "post",
              data: {
                  action: "GetPatBirthAge",
                  agestr: agestr,
              },
          });
      },
      headerCellClassName({ column, columnIndex }) {
          if (column.property == "physicyclename" || column.property == "specimen_name" || column.property == "deptname"|| column.property == "deptsubjectname" || column.property == "patsex" || column.property == "ageyear1" || column.property == "ageyear2" || column.property == "diag_icd" || column.property == "hospname") {
              return "col-blue";
          }
      },
      operatemdl(k) {
          if (k == 1) {
              if (!this.Qrptunitid) {
                  this.$alert("请选择报告单元！").then(() => { this.$refs.rptunitSelect.$refs.ddlrptunitSelect.focus(); });
                  return;
              }
              if(!this.rptitemcode) {
                  this.$alert("请选择报告项目！").then(() => { this.$refs.rptitemSelect.focus(); });
                  return;
              }
              //新增
              this.resetSeq();
              let xTable1date = this.$refs.xTable.tableData;
              let len = (xTable1date.length + 1) * 10;
              this.$refs.xTable
                  .insert({
                      rptunitid: this.Qrptunitid,
                      rptunitname: this.Qrptunitname,
                      rpt_itemcode: this.rptitemcode,
                      rpt_itemname: this.rptitemname,
                      itemcode_en: this.itemcodeen,
                      patsex: "All",
                      physicycle: "All",
                      physicyclename: "",
                      ageyear1: "-1",
                      ageyear2: "-1",
                      specimen_code: "All",
                      specimen_name: "",
                      deptno: "All",
                      deptname: "",
                      deptsubject: "All",
                      deptsubjectname: "",
                      hospcode: "All",
                      hospname: "All",
                      diag_icd: "All",
                      seq: len,
                      limit_l: "",
                      limit_h: "",
                      warn_l: "",
                      warn_h: "",
                      limit_rule: "",
                      txtresultlist: "",
                      onlyfirst: "0",
                      alert_rule: "",
                      resetbypatwardflag: "0",
                  })
                  .then(({ row }) => {
                      this.$nextTick(() => {
                          this.curselectrow = row;
                          this.$refs.xTable.setCurrentRow(row);
                          this.$refs.xTable.setActiveRow(row, "patsex");
                      });
                  });
              this.actionindex = 1; //新增
          } else if (k == 2) {
              //修改
              this.actionindex = 2; //新增
              this.perEditflag = true;
          } else {
              this.actionindex = 3;
              //删除
              try {
                  var delrow = this.$refs.xTable.getCurrentRow();
                  if (delrow) {
                      this.$confirm("确定要删除这条数据吗？", "提示", {
                          confirmButtonText: "确定",
                          cancelButtonText: "取消",
                          type: "warning",
                      })
                          .then(() => {
                              var alld = this.$refs.xTable.tableData;
                              var rowindex = alld.indexOf(delrow);
                              this.$refs.xTable.remove(delrow);
                              let havedata = this.$refs.xTable.tableData;
                              if (havedata.length > 0) {
                                  if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                                  let selectrow = havedata[rowindex];
                                  this.$refs.xTable.setCurrentRow(selectrow);
                              }
                              this.resetSeq();
                          })
                          .catch(() => {});
                  }
              } catch (e) {
                  console.log("error", e);
              }
          }
      },
      FunScrollY() {
          this.$nextTick(() => {
              var alldataLen = this.$refs.xTable.tableData.length;
              let L = this.$refs.xTable.getTableData().fullData[alldataLen - 1];
              this.$refs.xTable.scrollToRow(L);
          });
      },
      saverecord() {
          // let xTable1date = this.$refs.xTable.tableData;
          // xTable1date.sort((a, b) => {
          //     return Number(a.seq) - Number(b.seq);
          // });

          let data = this.$refs.xTable.getRecordset();

          //let filterdata = xTable1date.filter((item) => !item.rptunitid == "" || item.rptunitid == "-1" || item.rptunitid == null || item.rpt_itemcode == "");
          // let filterdata = xTable1date.filter((item) => !item.rptunitid || !item.rpt_itemcode);
          // if (filterdata.length > 0) {
          //     this.$message.warning("保存的数据报告单元和报告项目不能为空，请开窗选择！");
          //     return false;
          // }
          //序号重整
          this.$tool
              .request({
                  url: "LIS/LIS1/LIS118",
                  method: "post",
                  data: {
                      action: "save",
                      urec: data,
                  },
              })
              .then((response) => {
                  if (response.errcode == "1") {
                      this.$message({
                          message: "操作成功！",
                          type: "success",
                      });
                      this.InitPageData();
                      // this.ruleid = response.ruleid;
                  } else {
                      this.$alert("保存失败！" + response.errmsg, "提示");
                  }
              });
      },
      tabledataup() {
          if (this.tempindex > 0) {
              let upData = this.$refs.xTable.tableData[this.tempindex - 1];
              let currentrow = this.$refs.xTable.tableData[this.tempindex];
              this.$refs.xTable.tableData.splice(this.tempindex - 1, 1);
              this.$refs.xTable.tableData.splice(this.tempindex, 0, upData);
              this.tempindex = this.tempindex - 1;
              this.$nextTick(() => {
                  this.$refs.xTable.setCurrentRow(currentrow);
              });
              this.resetSeq();
          } else {
              this.$message.info("已经是第一个了，无法再上移了哦~");
          }
      },
      tabledatadown() {
          if (this.tempindex !== this.$refs.xTable.tableData.length - 1) {
              let downData = this.$refs.xTable.tableData[this.tempindex + 1];
              let currentrow = this.$refs.xTable.tableData[this.tempindex];
              this.$refs.xTable.tableData.splice(this.tempindex + 1, 1);
              this.$refs.xTable.tableData.splice(this.tempindex, 0, downData);
              this.tempindex = this.tempindex + 1;
              this.$nextTick(() => {
                  this.$refs.xTable.setCurrentRow(currentrow);
              });
              this.resetSeq();
          } else {
              this.$message.info("已经是最后一个了，无法再下移了哦~");
          }
      },
      tabledatalast() {
          if (this.tempindex != this.$refs.xTable.tableData.length - 1) {
              let lastData = this.$refs.xTable.tableData[this.tempindex];
              this.$refs.xTable.tableData.splice(this.tempindex, 1);
              this.$refs.xTable.tableData.splice(this.$refs.xTable.tableData.length, 0, lastData);
              this.tempindex = this.$refs.xTable.tableData.length - 1;
              this.$nextTick(() => {
                  this.$refs.xTable.setCurrentRow(lastData);
              });
              this.resetSeq();
          } else {
              this.$message.info("已经是最后一个了，无法再下移了哦~");
          }
      },
      tabledatafirst() {
          if (this.tempindex > 0) {
              let firstData = this.$refs.xTable.tableData[this.tempindex];
              this.$refs.xTable.tableData.splice(this.tempindex, 1);
              this.$refs.xTable.tableData.splice(0, 0, firstData);
              this.tempindex = 0;
              this.$nextTick(() => {
                  this.$refs.xTable.setCurrentRow(firstData);
              });
              this.resetSeq();
          } else {
              this.$message.info("已经是第一个了，无法再上移了哦~");
          }
      },
      resetSeq() {
          let tabledata = this.$refs.xTable.tableData;
          if (tabledata.length > 0) {
              for (let i = 0; i < tabledata.length; i++) {
                  tabledata[i].seq = 10 * (i + 1);
              }
          }
      },
      popMultipleChk(e) {
          let temp = XEUtils.clone(this.rptunitOption, true);
          this.option1 = [];
          this.option2 = [];
          if (e != "") {
              let k = e.split(",");
              for (let i = 0; i < k.length; i++) {
                  let ndata = temp.find((m) => m.data.trim() == k[i]);
                  if (ndata != undefined && ndata != null) {
                      this.option2.push(ndata);
                  }
              }
              temp.forEach((item) => {
                  if (k.indexOf(item.data + "") < 0) {
                      this.option1.push(item);
                  }
              });
          } else {
              this.option1 = temp;
          }
          this.dialogMultipleVisible = true;
      },
      closedialog(value, name) {
          if (value != "close") {
              this.rptunitidcopy = value;
          }
          this.dialogMultipleVisible = false;
      },

      copyItem() {
          this.$tool
              .request({
                  url: "LIS/LIS1/LIS118",
                  method: "post",
                  data: {
                      action: "copy",
                      rptunitid: this.Qrptunitid,
                      torptunitid: this.rptunitidcopy,
                  },
              })
              .then((response) => {
                  if (response.errcode == "1") {
                      this.$message({
                          message: "操作成功！",
                          type: "success",
                      });
                      this.CopyShow = false;
                      if (response.msg != "") {
                          var copyarr = response.msg.split("&&");
                          this.copymsg = [];
                          if (copyarr.length > 0) {
                              for (let i = 0; i < copyarr.length; i++) {
                                  if (copyarr[i] != "") this.copymsg.push(copyarr[i]);
                              }
                          }
                          this.dialogCopyMsgVisible = true;
                      }
                      this.InitPageData();
                      //复制之后刷新所有节点
                      var node = this.$refs.treenodes.getNode(-9999);
                      this.refreshTreeNode(node, false);
                      // this.ruleid = response.ruleid;
                  } else {
                      this.$alert("保存失败！" + response.errmsg, "提示");
                  }
              });
      },
      ShowCopyDia() {
          this.CopyShow = true;
          this.rptunitidcopy = "";
      },
  },
};
</script>

<style scoped>
.pagetop {
  width: 100%;
  height: 35px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 40px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

.middle-center {
  position: absolute;
  height: 100%;
  left: 0px;
  right: 0px;
  overflow: auto;
}

.table-bottom {
  font-size:12px;
  padding-right: 30px;
  padding-bottom: 10px;
  text-align:right;
}

.enumText {
  font-size: 14px;
}

.table1style tr td {
  padding: 0px 2px 0px 5px;
}
::v-deep .middle-center tr.vxe-body--row.row-modify {
  color: blue !important;
}
::v-deep .middle-center .vxe-header--column.col-blue {
  background-color: #2db7f5;
  color: #fff;
}
::v-deep.middle-center tr td div .el-input__inner {
  border: 1px solid rgba(255, 254, 254, 0) !important;
  background-color: rgba(255, 254, 254, 0) !important;
}
</style>
